<template>
  <div>
    <el-table v-loading="tableLoading" class="gl_table_noBorder" size="mini" :data="tableData">
      <el-table-column label="班级名称" align="center" prop="className" />
      <el-table-column label="关联课程" align="center" prop="courseName" />
      <el-table-column label="上课时间" align="center">
        <template slot-scope="scope">
          <div v-if="scope.row.courseDate">
            <span>{{ scope.row.courseDate | FormatDate('yyyy-MM-dd') }}</span>
            <span>
              {{ 10 > scope.row.startHour ? '0' + scope.row.startHour : scope.row.startHour }}:{{ 10 > scope.row.startMinute ? '0' + scope.row.startMinute : scope.row.startMinute }} -
              {{ 10> scope.row.endHour ? '0' + scope.row.endHour : scope.row.endHour }}:{{ 10 > scope.row.endMinute ? '0' + scope.row.endMinute : scope.row.endMinute }}
            </span>
          </div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <el-table-column label="人数" align="center" prop="studentCount" />
      <el-table-column label="更换教练">
        <template slot-scope="{ row }">
          <el-button type="text" size="mini" style="color:#1990FF" @click="replace(row)">更换</el-button>
        </template>
      </el-table-column>
    </el-table>
    <CourseRe ref="course" :course-id="courseid" />
    <el-row class="gl_pt_20" style="text-align: right;">
      <el-pagination
        :current-page="Api_GET_ClubCoachCoachCourseSchedulesQO.Page"
        :page-size="Api_GET_ClubCoachCoachCourseSchedulesQO.MaxResultCount"
        :total="totalPage"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
  </div>
</template>

<script>
import CourseRe from './courseReplace.vue';
import { api_GET_ClubCoachCoachCourseSchedules } from '@/extend/api/hallswaggerApi/app.js';
import { Api_GET_ClubCoachCoachCourseSchedulesQO } from '@/lib/form/hall/swaggerForm';
import { mapActions } from 'vuex';
export default {
  components: {
    CourseRe
  },
  data() {
    return {
      tableLoading: false,
      currentPage: 1,
      totalPage: 0,
      courseid: '',
      Api_GET_ClubCoachCoachCourseSchedulesQO: new Api_GET_ClubCoachCoachCourseSchedulesQO(), // 教练
      tableData: []
    };
  },
  created() {
    this.getcourseList();
  },
  methods: {
    ...mapActions({ getDict: 'dict/getDict', getDictByType: 'dict/getDictByType' }),
    replace(row) {
      console.log(row);
      this.$refs.course.selectable = '';
      this.$refs.course.currentMember = [];
      this.$refs.course.dialogVisible = true;
      this.$refs.course.courseScheduleId = row.id;
    },
    // 获取教练所授课程列表
    getcourseList(page) {
      this.Api_GET_ClubCoachCoachCourseSchedulesQO.Sorting = 'CourseDate,StartHour,StartMinute ASC';
      this.tableLoading = true;
      this.Api_GET_ClubCoachCoachCourseSchedulesQO.Page = page || 1;
      this.Api_GET_ClubCoachCoachCourseSchedulesQO.SkipCount = (this.Api_GET_ClubCoachCoachCourseSchedulesQO.Page - 1) * this.Api_GET_ClubCoachCoachCourseSchedulesQO.MaxResultCount;
      this.Api_GET_ClubCoachCoachCourseSchedulesQO.CoachId = this.$route.query.id;
      api_GET_ClubCoachCoachCourseSchedules(this.Api_GET_ClubCoachCoachCourseSchedulesQO).then(res => {
        console.log(res);
        this.tableLoading = false;
        this.tableData = res.items;
        this.totalPage = res.totalCount;
      }, error => {
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    sizeChange(MaxResultCount) {
      this.Api_GET_ClubCoachCoachCourseSchedulesQO.MaxResultCount = MaxResultCount;
      this.getcourseList();
    },
    pageIndexChange(currentPage) {
      this.getcourseList(currentPage);
    }
  }
};
</script>

<style>

</style>
